<?php
/**
 * Created by PhpStorm.
 * User: 申霖
 * Date: 2019/8/27 0027
 * Time: 下午 9:27
 */

/**
 * 文件大小转换
 * @param $key
 * @return string
 */
function trans_byte($key)
{
    $KB = 1024;
    $MB = 1024 * $KB;
    $GB = 1024 * $MB;
    $TB = 1024 * $GB;
    if($key < $KB) {
        return $key . "B";
    }
    elseif($key < $MB) {
        return round($key / $KB, 2) . "KB";
    }
    elseif($key < $GB) {
        return round($key / $MB, 2) . "MB";
    }
    elseif($key < $TB) {
        return round($key / $GB, 2) . "GB";
    }
    else {
        return round($key / $TB, 2) . "TB";
    }
}

/**
 * 资源的存储类型转换
 * @param $key
 * @return mixed
 */
function change_type($key)
{
    $arr = array(0 => '普通存储', 1 => '低频存储');
    return $arr[$key];
}

/**
 * 文件的存储状态转换
 * @param $key
 * @return mixed
 */
function change_status($key)
{
    $arr = array(0 => '启用', 1 => '禁用');
    return $arr[$key];
}
